﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class guChina_shopping33 : System.Web.UI.Page
{
    public string orderId="";
    public string productname = "";
    public string pwd ="";
    public string resultmsg=""; 
    public string endtime="";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            pay.BLL.OrderBLL orderbll = new pay.BLL.OrderBLL();
            pay.DAL.OrderDAL orderdal = new pay.DAL.OrderDAL();
            if (Request["orderId"] != null && Request["msg"] != null)
            {
               // orderId = Request["orderId"].ToString();
                orderId = Request["orderId"].ToString().Split(',')[0];
                string result_msg = Request["msg"].ToString();
                if (result_msg.Equals("success"))
                {
                    if (orderbll.UpdateOrderSucess(orderId) == true)
                    {
                        pay.BLL.OrderDetailBLL ordetail_bll = new pay.BLL.OrderDetailBLL();
                        pay.Entity.Web_Order orders = orderbll.GetOrderByOrderNumber(orderId);
                        if (orders.SourceType == 3) //标识为炒股大赛商品
                        {
                            //id:49 为6各月版， 50为12个月
                            WebService.emoneybusiness eb = new WebService.emoneybusiness();
                            List<pay.Entity.OrderDetails> ordersdetail = new List<pay.Entity.OrderDetails>();
                            ordersdetail = ordetail_bll.GetOrderByOrderNumber(orderId);
                            int usetime = 0;
                            string tel = "";
                            foreach (var c in ordersdetail)
                            {
                                switch (c.Productid)
                                {
                                
                                    case 54:   //益盟操盘手专业版12个月版(1元版)
                                        usetime = 12;
                                        productname = GetProductName(54);
                                        break;
                                    case 55:   //益盟操盘手专业版12个月版(99元版)
                                        usetime = 12;
                                        productname = GetProductName(55);
                                        break;
                                    case 56:   //益盟操盘手专业版12个月版(199元版)
                                        usetime = 12;
                                        productname = GetProductName(56);
                                        break;
                                    case 57:   //益盟操盘手专业版12个月版(299元版)
                                        usetime = 12;
                                        productname = GetProductName(57);
                                        break;
                                    case 58:   //益盟操盘手专业版12个月版(399元版)
                                        usetime = 12;
                                        productname = GetProductName(58);
                                        break;
                                    default:
                                        break;

                                }
                            }
                            pay.BLL.OrderDetailBLL dbl = new pay.BLL.OrderDetailBLL();
                            if (Request["ext1"] == null || Request["ext1"] == "")
                            {
                                return;
                            }

                            tel = Request["ext1"].ToString();//获取支付页面传递过来的电话号码
                            string reValue = eb.QQ_AddFee(tel, usetime); //激活或延长用户软件使用时间
                            //string reValue = dbl.GetActiveUserPwd(tel, usetime);
                            if (string.IsNullOrEmpty(reValue))
                            {
                                return;
                            }//if 用户还没有激活
                            try
                            {   
                                
                                string msg="恭喜您！您已成功秒杀【"+productname+"】软件一套,";
                                msg += "系统将自动延长您的使用期限！如有任何疑问,可拨打400-670-6888";
                                eb.SendMsg_Yicai(tel,msg);//发送短信
                            }
                            catch
                            { }

                        }// if 炒股大赛产品
                        else
                        {
                            Response.Redirect("http://pay.emoney.cn/shopping3.aspx?orderID=" + orderId);

                        }//else 非炒股大赛产品

                    }// if 数据库状态更新为已支付
                    else
                    {
                        Response.Write("<script>alert('订单状态更新出错!');</script>");
                       
                    }


                }//if 支付状态为成功



            }//if 订单编号不为空

            else
            {
                Response.Write("<script>alert('对不起，该订单尚未完成付款！');window.location.href='shopping22.aspx'; window.opener = null;window.close();</script>");
            }//未完成支付


        }
    }


    private string GetProductName(int productid)
    {
        pay.BLL.ProductBLL productbll = new pay.BLL.ProductBLL();
        pay.Entity.Product product = productbll.GetElementById(productid);
        return product.Productname;
    }//获取商品名称


}